
package finalproject.client;

import java.util.List;

import finalproject.client.ProjectService;
import finalproject.client.ProjectServiceAsync;
import finalproject.shared.Docent;
import finalproject.shared.Vak;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;


public class VakClass {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    VakGui gui;
    
   
    void listVakken() {
    	
    	// verzamel de aanwezige docenten voor de gui
    	projectService.listDocenten(new AsyncCallback<List<Docent>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListVakkenFailed(caught);
                    	// lege lijst
                    	List<Docent> result = null;
                    	gui.service_docentenListRetrievedFromService(result);
                    }
        
                    public void onSuccess(List<Docent> result) {
                        gui.service_docentenListRetrievedFromService(result);
                    }
        }
        );
    	
    
    
	projectService.listVakken(new AsyncCallback<List<Vak>> () {
        public void onFailure(Throwable caught) {
            gui.service_eventListVakkenFailed(caught);
        }

        public void onSuccess(List<Vak> result) {
            gui.service_eventListRetrievedFromService(result);
        }    
	}

);

    }
    void addVak(final Vak vak) {
    	projectService.addVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddVakSuccessful();
            }
        }
        );    
    }

 
    void updateVak(final Vak vak) {
    	projectService.updateVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }
        ); 
    }

  
    void removeVak(final Vak vak) {
    	projectService.removeVak(vak, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveVakFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveVakSuccessful();
            }
        }
        );     
    }
    
}
